package main

import (
	"server/common"
	"server/services/access"
	"server/services/online"
	"server/services/room"
	"strconv"
)

var LISTEN_ADDR = ":" + strconv.Itoa(common.ACCESS_SERVER_PORT)

func main() {
	common.InitLogger()

	dispatcher := common.NewMonoMsgDispatcher()

	accessService := access.NewAccessService(dispatcher)
	if err := accessService.Init(); err != nil {
		common.Logger(common.MODULE_COMMON).Fatalf("Failed to initialize access service: %v", err)
	}

	onlineService := online.NewOnlineService(dispatcher)
	if err := onlineService.Init(); err != nil {
		common.Logger(common.MODULE_COMMON).Fatalf("Failed to initialize online service: %v", err)
	}

	roomService := room.NewRoomService(dispatcher)
	if err := roomService.Init(); err != nil {
		common.Logger(common.MODULE_COMMON).Fatalf("Failed to initialize room service: %v", err)
	}

	// 阻塞等待服务退出
	if err := accessService.Start(LISTEN_ADDR); err != nil {
		common.Logger(common.MODULE_COMMON).Fatalf("Failed to start access service: %v", err)
	}

	common.Logger(common.MODULE_COMMON).Infof("Access service exited")
}
